﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using WebMatrix.WebData;
using System.Data.Entity.Infrastructure;
using OES.Models;

using System.Data.Entity;

namespace OES
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {



            AreaRegistration.RegisterAllAreas();
            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            AuthConfig.RegisterAuth();

            using (var context = new DataContext())
            {
                if (!context.Database.Exists())
                {
                    context.Database.CreateIfNotExists();


                    WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", true);
                    WebSecurity.CreateUserAndAccount("sakkas", "a99a55");
                    WebSecurity.Login("sakkas", "a99a55");
                    var courses = new List<Course>
            {
                new Course{UserID=1,Name="İngilizce",CreateDate=DateTime.Now},
                new Course{UserID=1,Name="Türkçe",CreateDate=DateTime.Now},
                new Course{UserID=1,Name="Bilgisayar",CreateDate=DateTime.Now},
               new Course{UserID=1,Name="GRE",CreateDate=DateTime.Now} ,
               new Course{UserID=1,Name="Tarih",CreateDate=DateTime.Now}
            
            };
                    courses.ForEach(c => context.Courses.Add(c));
                    context.SaveChanges();
                    var exams = new List<Exam>
            {
                new Exam{Name="sınav 1",CourseID=1,Duration=120,StartTime=DateTime.Now,FinishTime=DateTime.Now},
                new Exam{Name="sınav 2",CourseID=1,Duration=120,StartTime=DateTime.Now,FinishTime=DateTime.Now},
                new Exam{Name="sınav 1",CourseID=2,Duration=120,StartTime=DateTime.Now,FinishTime=DateTime.Now}
            , new Exam{Name="GRE Computer Science",CourseID=4,Duration=120,StartTime=DateTime.Now,FinishTime=DateTime.Now}

            };
                    exams.ForEach(e => context.Exams.Add(e));
                    context.SaveChanges();
                    var type = new List<Question_Type>
            {
                new Question_Type{Question_TypeName="Çoktan seçmeli"},
            new Question_Type{Question_TypeName="Çoktan çoklu"},
            new Question_Type{Question_TypeName="Doğru Yanlış"},
            };
                    type.ForEach(t => context.Question_Types.Add(t));
                    context.SaveChanges();


                    var question1 = new Question { ExamId = 4, Question_TypeId = 1, Question_Text = "<p>Consider the following pseudocode of the recursive function goAgain. &nbsp;<br />&nbsp;&nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// assume N is a positive integer &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;integer goAgain ( integer a, integer N ) &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ( N == 1 ) then &nbsp;&nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return a &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else &nbsp;&nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return a + goAgain ( a, N/2 ) &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end &nbsp;<br />&nbsp;&nbsp;</p><p>What is the order of growth, as a function of N, of the number of times the function goAgain is recursively executed?&nbsp;</p>"};

                    context.Questions.Add(question1);
                    context.SaveChanges();
                    var Choices = new List<Choice>                   
                    {
                        new Choice{QuestionId=question1.QuestionId,TrueAnswer=true,ChoiceText="Ɵ(log N)"},
                        new Choice{QuestionId=question1.QuestionId,TrueAnswer=false,ChoiceText="Ɵ(N)"},
                        new Choice{QuestionId=question1.QuestionId,TrueAnswer=false,ChoiceText="Ɵ(N log N)"},
                        new Choice{QuestionId=question1.QuestionId,TrueAnswer=false,ChoiceText="Ɵ(N<sup>2</sup>)"},
                        new Choice{QuestionId=question1.QuestionId,TrueAnswer=false,ChoiceText="Ɵ(N<sup>3</sup>)"}

                    };
                    Choices.ForEach(c => context.Choices.Add(c));
                    context.SaveChanges();

                    var question2 = new Question { ExamId = 4, Question_TypeId = 1, Question_Text = "<p>Consider the binary heap shown below that uses an array a[] = [9,7,4,2,6,1,3] to store its elements.</p><p><img  src=\"/deneme/20130107-15012762.jpg\" /></p><p>What will be the values of the remaining elements in the array after one delete-max operation from the heap?</p>"};
                    context.Questions.Add(question2);
                    context.SaveChanges();
                    var Choices2 = new List<Choice>                   
                    {
                        new Choice{QuestionId=question2.QuestionId,TrueAnswer=false,ChoiceText="[7,4,2,6,1,3]"},
                        new Choice{QuestionId=question2.QuestionId,TrueAnswer=false,ChoiceText="[7,4,6,2,1,3]"},
                        new Choice{QuestionId=question2.QuestionId,TrueAnswer=false,ChoiceText="[7,4,6,2,3,1]"},
                        new Choice{QuestionId=question2.QuestionId,TrueAnswer=false,ChoiceText="[7,6,4,2,1,3]"},
                        new Choice{QuestionId=question2.QuestionId,TrueAnswer=true,ChoiceText="[7,6,4,2,3,1]"}

                    };
                    Choices2.ForEach(c => context.Choices.Add(c));
                    context.SaveChanges();
                  
                    var question3 = new Question { ExamId = 4, Question_TypeId = 1, Question_Text = "<p>Assume that any n-bit positive integer x is stored as a linked list of bits so that the first element of the list&nbsp;is the least significant bit. For example, x=14=1110<sub>2</sub> is stored as the linked list (0, 1, 1, 1 )of size n=4.<br />For this data structure, the operation that replaces x by&nbsp;<img alt=\"\" src=\"/deneme/20130107-16014250.jpg\" /><br />can be done in</p>" };
                    context.Questions.Add(question3);
                    context.SaveChanges();
                    var Choices3 = new List<Choice>                   
                    {
                        new Choice{QuestionId=question3.QuestionId,TrueAnswer=true,ChoiceText="Ɵ(1) steps "},
                        new Choice{QuestionId=question3.QuestionId,TrueAnswer=false,ChoiceText="Ɵ(log n) steps"},
                        new Choice{QuestionId=question3.QuestionId,TrueAnswer=false,ChoiceText="Ɵ(n) steps"},
                        new Choice{QuestionId=question3.QuestionId,TrueAnswer=false,ChoiceText="Ɵ(n log n ) steps "},
                        new Choice{QuestionId=question3.QuestionId,TrueAnswer=false,ChoiceText="Ɵ(n<sup>2</sup>) steps"}

                    };
                    Choices3.ForEach(c => context.Choices.Add(c));
                    context.SaveChanges();


                    var question4 = new Question { ExamId = 4, Question_TypeId = 1, Question_Text = "<p>​Consider the following nondeterministic finite state automaton over alphabet {x,y} with start state S.</p><p><img alt=\"\" src=\"/deneme/20130107-16015504.jpg\" style=\"opacity: 0.9; font-size: 13px; width: 225px; height: 84px; \" />​</p><p>Which of the following is the regular expression corresponding to the automaton above?</p>"};
                    context.Questions.Add(question4);
                    context.SaveChanges();
                    var Choices4 = new List<Choice>                   
                    {
                        new Choice{QuestionId=question4.QuestionId,TrueAnswer=false,ChoiceText="xxx+yyx"},
                        new Choice{QuestionId=question4.QuestionId,TrueAnswer=false,ChoiceText="x<sup>3</sup>y<sup>2</sup>x"},
                        new Choice{QuestionId=question4.QuestionId,TrueAnswer=false,ChoiceText="x<sup>*</sup>y<sup>*</sup>x"},
                        new Choice{QuestionId=question4.QuestionId,TrueAnswer=true,ChoiceText="xx<sup>*</sup>(x+y)y<sup>*</sup>x"},
                        new Choice{QuestionId=question4.QuestionId,TrueAnswer=false,ChoiceText="x<sup>*</sup>xy<sup>*</sup>x"}

                    };
                    Choices4.ForEach(c => context.Choices.Add(c));
                    context.SaveChanges();



                    var question5 = new Question { ExamId = 4, Question_TypeId = 1, Question_Text = "<p>Consider the following nondeterministic finite state automaton over alphabet{x, y} with start state S.</p><p><img alt=\"\" src=\"/deneme/20130107-16015504.jpg\" style=\"opacity: 0.9; font-size: 13px; width: 225px; height: 84px; \" /></p><p>Which of the following grammars over alphabet {x,y} generates the language recognized by the automaton above?</p>"};
                        context.Questions.Add(question5);
                    context.SaveChanges();

                    var Choices5 = new List<Choice>                   
                    {
                        new Choice{QuestionId=question5.QuestionId,TrueAnswer=false,ChoiceText="S→xT<br/>T→xT | xU | yU<br/>U→yU | xV"},
                        new Choice{QuestionId=question5.QuestionId,TrueAnswer=true,ChoiceText="S→xT<br/>T→xT | xU | yU<br/>U→yU | x"},
                        new Choice{QuestionId=question5.QuestionId,TrueAnswer=false,ChoiceText="S→xT | T<br/>T→xT | xU | yU | T | U<br/>U→yU | xV | V | x"},
                        new Choice{QuestionId=question5.QuestionId,TrueAnswer=false,ChoiceText="S→xV<br/>T→xT | yU<br/>U→yU | xV"},
                        new Choice{QuestionId=question5.QuestionId,TrueAnswer=false,ChoiceText="S→xT<br/>T→xT |T<br/>U→yU | V<br/>V→xV | x"}

                    };
                    Choices5.ForEach(c => context.Choices.Add(c));
                    context.SaveChanges();






                    //  WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);
                }
                else

                    WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", true);
            }


        }
    }
}